﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PEUtils;
using UnityEngine;

namespace HotFix
{
    class TestDel
    {
        // Unity 端定义的委托
        public static TestDelegateMeth delegateMethod;
        public static TestDelegateFunction delegateFunc;

        public static Action<string> delegateAction;
        public static void Initialize()
        {
            delegateMethod = Method;
            delegateFunc = Function;
            delegateAction = ActionDel;
            PELog.InitSettings(new LogConfig(){loggerEnum = LoggerType.Unity});
        }

        private static void ActionDel(string a)
        {
            PELog.ColorLog(LogColor.Magenta,"TestDele ActionDel a = "+ a);
        }

        public static void RunTest()
        {
            if (delegateFunc != null)
            {
                delegateFunc(25);
            }

            if (delegateMethod != null)
            {
                delegateMethod(28);
            }

            if (delegateAction != null)
            {
                delegateAction("JoeManba");
            }
        }

        private static void Method(int a)
        {
            PELog.ColorLog(LogColor.Magenta,"TestDele Method a = "+ a);
        }

        private static string Function(int a)
        {
            PELog.ColorLog(LogColor.Magenta,"TestDele Function a = "+ a);
            return a.ToString();
        }
        
        public static void Initialize2()
        {
            ILRuntimeManager.Instance.DelegateMethod = Method;
            ILRuntimeManager.Instance.DelegateFunc = Function;
            ILRuntimeManager.Instance.DelegateAction = ActionDel;
            PELog.InitSettings(new LogConfig(){loggerEnum = LoggerType.Unity});
        }
        
        public static void RunTest2()
        {
            if (ILRuntimeManager.Instance.DelegateMethod != null)
            {
                ILRuntimeManager.Instance.DelegateMethod(25);
            }

            if (ILRuntimeManager.Instance.DelegateFunc != null)
            {
                ILRuntimeManager.Instance.DelegateFunc(28);
            }

            if (ILRuntimeManager.Instance.DelegateAction != null)
            {
                ILRuntimeManager.Instance.DelegateAction("JoeManba");
            }
        }
    } 
}
